//
//  IndexItem.m
//  jiuquan
//
//  Created by geng on 14-11-27.
//  Copyright (c) 2014年 geng. All rights reserved.
//

#import "OAIndexItem.h"

@implementation OAIndexItem
{
    UITapGestureRecognizer*tap;
}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        self.clipsToBounds=YES;
        _normalColor=UIColorFromRGB(0x808080);
        _selectedColor=BLUE_COLOR;
        _smallView=[[UIImageView alloc]init];
        [self addSubview:_smallView];
        
        _title=[[UILabel alloc]init];
        _title.font=FONT_BOLD_10;
        _title.textAlignment=NSTextAlignmentCenter;
        _title.backgroundColor=[UIColor clearColor];
        [self addSubview:_title];
        // Initialization code
    }
    return self;
}
-(void)setIsTap:(int)isTap
{
    if (isTap==2) {
        self.userInteractionEnabled=YES;
        _smallView.userInteractionEnabled=YES;
        tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectedView:)];
        tap.numberOfTapsRequired=1;
        tap.numberOfTouchesRequired=1;
        [self addGestureRecognizer:tap];
        
    }
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    if (iPhone6plus) {
        _smallView.frame=CGRectMake((self.width-RESIZE_UI(22))/2,(self.height-RESIZE_UI(15)-RESIZE_UI(22))/2, RESIZE_UI(22), RESIZE_UI(22));
        _title.frame=CGRectMake(0,self.height-RESIZE_UI(15), self.width, RESIZE_UI(15));

    }
    else if (isIPhone5||isIPhone4)
    {
        _smallView.frame=CGRectMake((self.width-RESIZE_UI(27))/2,(self.height-RESIZE_UI(16)-RESIZE_UI(27))/2, RESIZE_UI(27), RESIZE_UI(27));
        _title.frame=CGRectMake(0,self.height-RESIZE_UI(16), self.width, RESIZE_UI(16));
    }
    else
    {
        _smallView.frame=CGRectMake((self.width-RESIZE_UI(25))/2,(self.height-RESIZE_UI(15)-RESIZE_UI(25))/2, RESIZE_UI(25), RESIZE_UI(25));
        _title.frame=CGRectMake(0,self.height-RESIZE_UI(15), self.width, RESIZE_UI(15));

    }
    
}
//- (void)setSelected:(BOOL)isSelected
//{
//    if (isSelected) {
//        if (self.selectedImage!=nil) {
//            _smallView.image=self.selectedImage;
//            _title.textColor=_selectedColor;
//        }
//        
//        
//        self.highlighted=YES;
//    }
//    else
//    {
//        if (self.normalImage!=nil) {
//            _smallView.image=self.normalImage;
//            _title.textColor=_normalColor;
//        }
//        
//        
//        self.highlighted=NO;
//    }
//}

- (void)setSelected:(BOOL)isSelected
{
    if (isSelected) {

            _smallView.image=self.selectedImage;
            _title.textColor=_selectedColor;
        
    }
    else
    {

            _smallView.image=self.normalImage;
            _title.textColor=_normalColor;
        
    }
}

-(void)selectedView:(id)sender
{
    if ([_delegate respondsToSelector:@selector(seletedItem:)]) {
        [_delegate seletedItem:self];
    }
}

-(void)dealloc
{
    _delegate=nil;
    if (tap!=nil) {
        [tap removeTarget:self action:@selector(selectedView:)];
        [self removeGestureRecognizer:tap];
    }
    
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
